class Descriptor:
    def __init__(self):
        self.age = 0

    def __get__(self, instance, owner):
        print(f"get, instance={instance}")
        if self.age < 18:
            return 18
        else:
            return self.age

    def __set__(self, instance, value):
        print(f"set, instance={instance}")
        if value < 18:
            self.age = 18
        else:
            self.age = value

    def __delete__(self, instance):
        pass


# 通过描述符，可以实现属性委托的效果，在代理类中增加对属性的安全访问与逻辑控制
class Adult:
    age = Descriptor()


if __name__ == '__main__':
    adult = Adult()
    adult.age = 16
    age = adult.age
    print(f"age={age}")
